from primes import erastothenes
from itertools import count

def nrsums(sum, candidates, d = dict()):
    max, rest = candidates[0], candidates[1:]
    
    if [] == rest:
        if 0 == sum % max: return 1
        else: return 0

    if (sum, max) in d: return d[(sum, max)]
    
    result = 0
    
    for n in xrange(sum // max, -1, -1):
        result += nrsums(sum - n * max, rest, d)
        
    d[(sum, max)] = result

    return result

for n in count(2):
    primes = erastothenes(n)
    primes.reverse()
    if 5000 <= nrsums(n, primes):
        print n
        break
